# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
  include SimpleCaptcha::ControllerHelpers
  include ApplicationHelper
  include ProfileHelper
  include FriendshipHelper
  include RequirementHelper
  include PhotoHelper
  include Site::RequirementHelper
  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
  before_filter :check_authorization
  #通过唯一的cookie名称来识别相应的session数据
  session :session_key => '_fendu_session_id'
  def check_authorization
     authorization_token = cookies[:authorization_token]
     if authorization_token and not logged_in?
       user = User.find_by_authorization_token(authorization_token)
       user.login!(session) if user
     end
  end
  
  def param_posted?(symbol)
     request.post? and params[symbol]
  end
 
  def protect
    unless logged_in?
      flash[:notice] = "请登录"
      session[:protect_page] = request.request_uri
      redirect_to :action => "login", :controller => "admin/users"
      return false
    end
    @login_user = User.find(session[:user_id])
  end
end
